package CA;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import junit.framework.TestCase;

public class FileClean_Test extends TestCase {

	private final String MainExaminLocation = System.getProperty("user.dir") + "/UnitTestData/";
	
	
	
	protected void setUp() throws Exception {
		super.setUp();
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}
	
	
	// Test could probably be broken up into smaller components
	public void testRun() throws IOException, InterruptedException
	{
		FileCleaning fc = new FileCleaning();
		Helper h = new Helper();
		String compareFile = MainExaminLocation+"/FileClean/Remove/";
		CrashSuper cs = new CrashSuper();

		
		// Make sure everything is setup properly
		File childCopy1 = new File(compareFile+"/lala/");
		File childCopy2 = new File(compareFile+"/lala2/");
		File parentCopy = new File(compareFile+"/noscantest/");
		fc.copyFolder(parentCopy, childCopy1);
		fc.copyFolder(parentCopy, childCopy2);
		
		// Test the number of initial files in the folders to make sure everything is setup properly
		File fa0=new File(compareFile+"lala/0.txt");
		File fa1=new File(compareFile+"lala/1.txt");
		File fa2=new File(compareFile+"lala/2.txt");
		File fa3=new File(compareFile+"lala/3.txt");
		File fa4=new File(compareFile+"lala/4.txt");
		
		File fb0=new File(compareFile+"lala2/0.txt");
		File fb1=new File(compareFile+"lala2/1.txt");
		File fb2=new File(compareFile+"lala2/2.txt");
		File fb3=new File(compareFile+"lala2/3.txt");
		File fb4=new File(compareFile+"lala2/4.txt");
		
		// Now make sure that they contain the correct number of missing information
		assertEquals(h.getMissingModuleInfoByFile(fa0),0);
		assertEquals(h.getMissingModuleInfoByFile(fa1),1);
		assertEquals(h.getMissingModuleInfoByFile(fa2),2);
		assertEquals(h.getMissingModuleInfoByFile(fa3),3);
		assertEquals(h.getMissingModuleInfoByFile(fa4),4);
		assertEquals(h.getMissingModuleInfoByFile(fb0),0);
		assertEquals(h.getMissingModuleInfoByFile(fb1),1);
		assertEquals(h.getMissingModuleInfoByFile(fb2),2);
		assertEquals(h.getMissingModuleInfoByFile(fb3),3);
		assertEquals(h.getMissingModuleInfoByFile(fb4),4);
		
		
		// Run script to remove the files
	
		
		
		
		
		// Verify the results
	//	File childCopy1 = new File("C:/SignatureOutput/noscan/100/Perfect/lala/");
	//	File childCopy2 = new File("C:/SignatureOutput/noscan/100/Perfect/lala2/");
		List<FileInfo> fileList = new ArrayList<FileInfo>();
		fileList=cs.getFileList(compareFile);
		
		
		fc.Run(compareFile);	
	
		// check to make sure everything was removed properly
		assertEquals(fileList.size(),2);
		
//T  	getTotalNumberOfFoldersWithMissingCrashInfo(List<FileInfo> fileList, boolean isExcludeMissing)
// 		isFileContainMissingInfoLines(String fileName)
//		isFileMissingStackInfo(FileInfo file)
//		List<File> getFileList(String parentLocation)
//T 		getTotalLinesInAllFiles(List<FileInfo> fileList, boolean isExcludeMissing)
//T		getTotalLinesMissingCrashInfoInAllFiles(List<FileInfo> fileList, boolean isExcludeMissing)
//T		getTotalNumberOfFolders(List<FileInfo> fileList, boolean isExcludeMissing)
		
		assertEquals(h.getTotalNumberOfFolders(fileList, false),2);
		assertEquals(h.getTotalLinesMissingCrashInfoInAllFiles(fileList, false),0);
		assertEquals(h.getTotalLinesInAllFiles(fileList, false),0);
		assertEquals(h.getTotalNumberOfFoldersWithMissingCrashInfo(fileList, false),0);
		
		
		
		//Re-copy over the items to set things up for next time
		// Do the following for cleanup up purposes during testing.
	//	File parentCopy = new File("C:/SignatureOutput/noscan/100/Perfect/noscantest/");
		
	//	fc.copyFolder(parentCopy, childCopy1);
	//	fc.copyFolder(parentCopy, childCopy2);
		
		
	}
	
	
	
	
	// 	public void DeleteFile(String fileName){
	// public void copyFolder(File src, File dest)

}
